package API.Collection.List.ArrayList.Basis.test;

import java.util.ArrayList;
import java.util.Scanner;

class User {
    private String id;
    private String name;
    private String password;

    public User() {
    }

    public User(String id, String name, String password) {
        this.id = id;
        this.name = name;
        this.password = password;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String toString() {
        return "User{id = " + id + ", name = " + name + ", password = " + password + "}";
    }
}

public class UserInfor {
    public static void addUser(ArrayList<User> list, ArrayList<String> idRecorder, char idPart2) {
        Scanner sc = new Scanner(System.in);
        String idPart1 = "00";
        User user = new User();
        user.setId(idPart1 + idPart2);
        idRecorder.add(idPart1 + idPart2);
        System.out.println("请输入用户姓名");
        user.setName(sc.next());
        sc.nextLine();
        System.out.println("请输入用户密码");
        user.setPassword(sc.nextLine());
        list.add(user);
    }

    public static String search(ArrayList<User> list, ArrayList<String> idRecorder, String id) {
        int judge = idRecorder.indexOf(id);
        if (judge != -1) {
            return list.get(judge).toString();
        } else {
            return "查无此人！";
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<User> list = new ArrayList<>();
        //暂时未学习哈希，使用ArrayList
        ArrayList<String> idRecorder = new ArrayList<>();
        char idPart2 = '1';
        int choice;
        boolean judgeWhile = true;
        while (judgeWhile) {
            choice = sc.nextInt();
            switch (choice) {
                case 1: {
                    addUser(list, idRecorder, idPart2);
                    idPart2++;
                    break;
                }
                case 2: {
                    String id = sc.next();
                    int num = idRecorder.indexOf(id);
                    idRecorder.remove(id);
                    list.remove(num);
                    break;
                }
                case 3: {
                    System.out.println("请输入要查找的id");
                    System.out.println(search(list, idRecorder, sc.next()));
                    break;
                }
                case 0:
                {
                    judgeWhile = false;
                    break;
                }
                default:
                {
                    System.out.println("输入错误，请重新输入");
                }
            }
        }
    }
}